package com.hongyuan.sellfitness.ui.home.fragment;

import android.annotation.SuppressLint;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProviders;

import com.hongyuan.sellfitness.BR;
import com.hongyuan.sellfitness.R;
import com.hongyuan.sellfitness.base.AppViewModelFactory;
import com.hongyuan.sellfitness.base.Constants;
import com.hongyuan.sellfitness.base.CustomFragment;
import com.hongyuan.sellfitness.databinding.FragmentGroupClassBinding;
import com.hongyuan.sellfitness.ui.home.view_mode.GroupClassViewModel;

public class StoreGroupClassFragment extends CustomFragment<FragmentGroupClassBinding, GroupClassViewModel> {

    private String os_id;

    @SuppressLint("SourceLockedOrientationActivity")
    @Override
    public void initParam() {
        super.initParam();
        getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        os_id = getBundle().getString("os_id");
    }

    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.fragment_group_class;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }


    @Override
    public GroupClassViewModel initViewModel() {
        //使用自定义的ViewModelFactory来创建ViewModel，如果不重写该方法，则默认会调用NetWorkViewModel(@NonNull Application application)构造方法
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getActivity().getApplication());
        return ViewModelProviders.of(this, factory).get(GroupClassViewModel.class);
    }

    @Override
    public void initView() {
        super.initView();
        //给RecyclerView添加Adpter，请使用自定义的Adapter继承BindingRecyclerViewAdapter，重写onBindBinding方法，里面有你要的Item对应的binding对象。
        // Adapter属于View层的东西, 不建议定义到ViewModel中绑定，以免内存泄漏
        //binding.setAdapter(new BindingRecyclerViewAdapter());

        setOnRefresh(binding.refresh,REFRESH_0X3);
        setEnableLoadMore(Constants.GET_COURSE_SUPER_LIST);
        setEnableRefresh(Constants.GET_COURSE_SUPER_LIST);
    }

    @Override
    public void initData() {
        super.initData();
        viewModel.setParams("os_ids",os_id);
        viewModel.requestData(Constants.GET_PLAN_DATE);
    }
}
